package com.agileboot.domain.system.notice.db;

import cn.hutool.core.stream.CollectorUtil;
import com.agileboot.domain.system.notice.dto.NoticeDTO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 通知公告表 服务实现类
 * </p>
 *
 * @author valarchie
 * @since 2022-06-16
 */
@Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNoticeEntity> implements SysNoticeService {

    @Override
    public Page<SysNoticeEntity> getNoticeList(Page<SysNoticeEntity> page, Wrapper<SysNoticeEntity> queryWrapper) {
        return this.baseMapper.getNoticeList(page, queryWrapper);
    }

    @Override
    public List<NoticeDTO> getNoticeList() {
        LambdaQueryWrapper<SysNoticeEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysNoticeEntity::getStatus,1);
        queryWrapper.orderByDesc(SysNoticeEntity::getCreateTime);
        List<SysNoticeEntity> sysNoticeEntities = this.baseMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(sysNoticeEntities)) return Collections.emptyList();
        return sysNoticeEntities.stream().map(NoticeDTO::new).collect(Collectors.toList());

    }

}
